﻿#ifndef CUSTOMWIDGET_H
#define CUSTOMWIDGET_H


#include<QPropertyAnimation>
#include<QDebug>
#include <QPushButton>
#include <QLineEdit>
#include <QRegularExpression>
#include <QRegularExpressionValidator>
#include <QSlider>
#include <QString>
#include<QTimer>
#include <QPixmap>
#include <QPainter>
#include <QPaintEvent>
#include <QMouseEvent>
#include <QResizeEvent>
#include <QFocusEvent>
#include<QAnimationGroup>
#include<QParallelAnimationGroup>
#include <QGraphicsOpacityEffect>
#include <QLabel>
#include <QVBoxLayout>

//**************************//
//ClickLabel
class ClickLabel:public QWidget{
    Q_OBJECT
private:
    const float margin=2.5;
    const int spacing= 5;
    QLabel *contentName;
    QWidget * bgWidget;
    QGraphicsOpacityEffect * bgOpac;

    //bool enabled=true;
    bool mousePressed=false;

    void enterEvent(QEnterEvent * event);
    void leaveEvent(QEvent * event);
protected:
    void mousePressEvent(QMouseEvent* event);

    void mouseReleaseEvent(QMouseEvent * event);
public:
    ClickLabel(const QString &name, QWidget *parent = nullptr);

signals:
    void clicked();


};
//*******************//
//EasyClickLabel
class EasyClickLabel:public QLabel{
    Q_OBJECT
private:
    bool MousePress=false;
public:
    EasyClickLabel(QWidget* parent);
    ~EasyClickLabel(){}
protected:
    void mousePressEvent(QMouseEvent * event);
    void mouseReleaseEvent(QMouseEvent * event);
signals:
    void clicked();
};
//*******************//
//textInputItem
class textInputItem : public QWidget{
    Q_OBJECT

private:
    const int margin = 10;
    const int spacing = 10;
    QLabel *itemName;
    QLineEdit *editor;
    QWidget *bgWidget;
    QWidget *indicator;
    QGraphicsOpacityEffect *opac;

    QString curText = "";
    bool mousePressed = false;
    bool onEditing = false;

    bool enabled = true;

    void enterEditEffect();
    void leaveEditEffect();

    void enterEvent(QEnterEvent *event);
    void leaveEvent(QEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void resizeEvent(QResizeEvent *event);
    //void focusOutEvent(QFocusEvent *event);

public:
    textInputItem(const QString &name, QWidget *parent = nullptr);
    QLineEdit* lineEditor(){return editor;}
    QString value(){return editor->text();}

    void setValue(const QString &text);
    void setValidator(QValidator *vali){editor->setValidator(vali);}
    void setEnabled(bool enable = true){enabled = enable;}

signals:
    void textEdited(QString text);
};

class messageInputItem:public QWidget{
    Q_OBJECT
private:
    const int margin=5;
    const int spacing=5;
    QLabel * itemName;
    QLineEdit * editor;
    QWidget* bgWidget;
    QWidget * indicator;
    QGraphicsOpacityEffect * opac;
    bool mousePressed =false;
    QString curText = "";
    bool onEditing= false;
    bool enabled=true;

    void enterEditEffect();
    void leaveEditEffect();

    void enterEvent(QEnterEvent *event);
    void leaveEvent(QEvent *event);
    void resizeEvent(QResizeEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

public:
    messageInputItem(const QString &name,QWidget * parent=nullptr);
    QString value(){return editor->text();}
    QLineEdit * getEditor(){return editor;}
     void setValue(const QString &text);
    void setValidator(QValidator *vali){editor->setValidator(vali);}
    void setEnabled(bool enable = true){enabled = enable;}
signals:
    void messageEdit(QString text);
};

//class singleLineEdit:public QLineEdit{
//    Q_OBJECT
//signals:
//    void next();//触发next信号 跳转setfocus到下一个singleLineEdit
//private slots:
//    void nextLE();//连接回车键 触发next信号
//public:
//    singleLineEdit(QWidget * parent=nullptr);
//};

#endif // CUSTOMWIDGET_H
